/*
 * @Author: zhengzhuang
 * @Date: 2020-05-18 11:43:27
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-08-06 16:24:32
 * @Description: In User Settings Edit
 * @FilePath: /C20Driver_1.0.0/lib/pages/user_module/my_qr_code.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/config/app_share.dart';
import 'package:C20Driver/model/get_share_info_model.dart';
import 'package:C20Driver/provider/driver_information.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/widget/app_share.dart';
import 'package:C20Driver/widget/spinkit.dart';
import 'package:provider/provider.dart';
import 'package:qr_flutter/qr_flutter.dart';

/// 我的二维码
class MyQrCode extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('我的二维码'),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.share, color: Colors.white),
            onPressed: () => AppShare.share(context, AppShareCode().appShare),
          ),
        ],
      ),
      backgroundColor: Color.fromARGB(255, 255, 226, 129),
      body: Container(
        child: FutureBuilder(
          future: Request.getShareInfo(),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            GetShareInfo qrcode = snapshot.data;
            if (snapshot.hasData) {
              return Stack(
                children: <Widget>[
                  Image.asset('assets/icon/myqrcodebg.png',
                      width: ScreenUtil().setWidth(750.0)),
                  Positioned(
                      top: ScreenUtil().setWidth(510.0),
                      left: ScreenUtil().setWidth(175.0),
                      child: Column(
                        children: <Widget>[
                          Container(
                            width: ScreenUtil().setWidth(400.0),
                            height: ScreenUtil().setWidth(400.0),
                            color: Colors.white,
                            child: QrImage(
                              data: qrcode.url +
                                  "?userId=${Provider.of<DriverInformation>(context).driverInfo.userId}",
                              version: QrVersions.auto,
                              size: 200.0,
                            ),
                          ),
                          SizedBox(height: ScreenUtil().setWidth(20.0)),
                          Text('微信扫一扫',
                              style: TextStyle(
                                  fontSize: ScreenUtil().setSp(30.0),
                                  color: Colors.black54)),
                        ],
                      )),
                ],
              );
            } else {
              return Spinkit();
            }
          },
        ),
      ),
    );
  }
}
